package org.yanghaokun.user.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.yanghaokun.basic.exception.BusinessException;
import org.yanghaokun.basic.util.AjaxResult;
import org.yanghaokun.user.service.IVerifyCodeService;

import java.util.Map;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {

    @Autowired
    private IVerifyCodeService verifyCodeService;
    //一定情况下Map能够代替类使用
    @PostMapping("/sendsms")
    public AjaxResult sendSms(@RequestBody Map<String,String> params) {
        //从床过来的参数中获取电话信息
        String phone = params.get("phone");
        String type = params.get("type");//用来区分是绑定还是注册
        try {
            verifyCodeService.sendSms(params);
            //发送失败
            return AjaxResult.me();

        }catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("发送失败" + e.getMessage());
        }
        catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统错误" + e.getMessage());
        }
    }
}
